from openpyxl import load_workbook
from config import exclePath



# exclePath = "../data/测试数据.xlsx"

def readExcleData(sheetName):
    """
    读取excle的数据
    """
    excle = load_workbook(exclePath)
    sheet = excle[sheetName]
    datas = []
    for row in sheet:
        data = []
        for i in row:
            data.append(i.value)
        datas.append(data)
    keys = datas.pop(0)
    datas_dict = []
    for data in datas:
        dict_data = {}
        for i in range(len(data)):
            value = data[i]
            dict_data.update({keys[i]:value})
        datas_dict.append(dict_data)
    return datas_dict


def writeExcleData(sheetName,cellName,value):
    """
    根据excle的坐标写入数据
    """
    excle = load_workbook(exclePath)
    sheet = excle[sheetName]
    sheet[cellName].value = str(value)
    excle.save(exclePath)




if __name__ == "__main__":
    data = readExcleData("登录")
    print(data)